package com.itheima.homework;

import java.sql.SQLOutput;
import java.util.Set;
import java.util.TreeSet;

public class Student implements Comparable<Student>{
    private String name;
    private String sex;
    private int age;

    public Student() {
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        int result = this.age- o.age;
       return result = result == 0 ? this.age- o.age : result;
    }
}

/**
 * 请按以下要求顺序编码：
 * 定义学生类Student，属性：姓名、性别、年龄
 * 定义测试类，及main()方法
 * 定义一个存储Student类型的Set集合
 * 创建以下三个Student对象
 * 张三,男,20
 * 李四,女,21
 * 张三,男,20
 * 将上述三个对象存储到Set集合中
 * 使用增强for遍历集合，获取每个Student对象，并打印属性值；
 * 请实现集合中不能存储姓名年龄相同的元素
 */
class Test{
    public static void main(String[] args) {
        Set<Student> ts = new TreeSet<>();
        Student s1 = new Student("张三","男",20);
        Student s2 = new Student("李四","女",21);
        Student s3 = new Student("张三","男",20);


        ts.add(s1);
        ts.add(s2);
        ts.add(s3);

        for (Student t : ts) {
            System.out.println(t);
        }
    }
}